import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description: 写一个递归方法，输入一个非负整数，返回组成它的数字之和
 * User: 15085202591
 * Date: 2022-11-03
 * Time: 21:16
 */
public class SumEachNum {
    private static int sumEach(int x){
       if(x <= 9){
           return x;
       }
       return x % 10 +sumEach(x/10);
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入一个整数：");
        while (sc.hasNextInt()){
            int n = sc.nextInt();
            System.out.println("和为"+sumEach(n));
            System.out.println("输入一个整数：");
        }
    }

}
